|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Fast Track Visual C++ 6.0 Programming
The code for ScannerView.h and ScannerView.cpp appears in Listing 7.1. Listing 7.1 ScannerView.h and ScannerView.cpp
// ScannerView.h : interface of the CScannerView class
//
/////////////////////////////////////////////////////////////////////////////
#if
!defined(AFX_SCANNERVIEW_H__BFF33AA1_A398_11D1_887F_D42B07C10710__INCLUDED_)
#define AFX_SCANNERVIEW_H__BFF33AA1_A398_11D1_887F_D42B07C10710__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CScannerView : public CView
{
protected: // create from serialization only
CScannerView();
DECLARE_DYNCREATE(CScannerView)
// Attributes
public:
CScannerDoc* GetDocument();
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CScannerView)
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CScannerView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
//{{AFX_MSG(CScannerView)
afx_msg void OnFileScanmemory();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
#ifndef _DEBUG // debug version in ScannerView.cpp
inline CScannerDoc* CScannerView::GetDocument()
{ return (CScannerDoc*)m_pDocument; }
#endif
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately
before the previous line.
#endif //
!defined(AFX_SCANNERVIEW_H__BFF33AA1_A398_11D1_887F_D42B07C10710__INCLUDED_)
// ScannerView.cpp : implementation of the CScannerView class
//
#include stdafx.h
#include Scanner.h
#include ScannerDoc.h
#include ScannerView.h
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CScannerView
IMPLEMENT_DYNCREATE(CScannerView, CView)
BEGIN_MESSAGE_MAP(CScannerView, CView)
//{{AFX_MSG_MAP(CScannerView)
ON_COMMAND(ID_FILE_SCANMEMORY, OnFileScanmemory)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CScannerView construction/destruction
CScannerView::CScannerView()
{
// TODO: add construction code here
}
CScannerView::~CScannerView()
{
}
BOOL CScannerView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CScannerView drawing
void CScannerView::OnDraw(CDC* pDC)
{
CScannerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
TEXTMETRIC tm;
pDC->GetTextMetrics(&tm);
for(int loop_index = 0; loop_index <= pDoc->number_lines; loop_index++){
pDC->TextOut(0, loop_index * tm.tmHeight, pDoc->text[loop_index]);
}
}
/////////////////////////////////////////////////////////////////////////////
// CScannerView printing
BOOL CScannerView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CScannerView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CScannerView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CScannerView diagnostics
#ifdef _DEBUG
void CScannerView::AssertValid() const
{
CView::AssertValid();
}
void CScannerView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CScannerDoc* CScannerView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CScannerDoc)));
return (CScannerDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CScannerView message handlers
void CScannerView::OnFileScanmemory()
{
// TODO: Add your command handler code here
CScannerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
MEMORY_BASIC_INFORMATION MemoryBasicInfo;
char CodeName[50], AddressString[50];
LPVOID lpBase = NULL;
for(LPVOID lpSearch = (LPVOID) 0x00400000; lpSearch < (LPVOID)
0xF0000000; lpSearch = (LPVOID) ((BYTE *) lpSearch + 4*1024)){
VirtualQuery(lpSearch, &MemoryBasicInfo, sizeof(MemoryBasicInfo));
if(lpBase != MemoryBasicInfo.AllocationBase){
lpBase = MemoryBasicInfo.AllocationBase;
if(GetModuleFileName((HINSTANCE)lpBase, CodeName, 50) != NULL){
pDoc->text[pDoc->number_lines] = CodeName;
sprintf(AddressString, is at location = %#x, lpBase);
pDoc->text[pDoc->number_lines++] += AddressString;
Invalidate();
}
}
}
}
Weve seen a lot of memory handling already, but theres more to come. In the next example, we let two processes communicate through shared memory, passing data from one to the other. Memory-Mapped FilesIn our next example, we work with memory-mapped files. A memory-mapped file is a region of memory, which can include the swap file, in which we place data that can be accessed by a number of programs. In this case, we type some data into a program.
----------------------------------------------
| |
|---------------------------------------------- |
| --------------------------- |
| |Here's the data... | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| -------------------------- |
| |
----------------------------------------------
|
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |